package lumis.service.portalmanagement.audit;

import lumis.doui.processaction.ProcessActionHandler;
import lumis.doui.source.Source;
import lumis.portal.PortalException;
import lumis.portal.audit.AuditManager;
import lumis.portal.manager.ManagerFactoryInternal;
import lumis.util.XmlUtil;

/**
 * Process action handler to perform audit configuration operations.
 *
 * @version $Revision: 13092 $ $Date: 2011-05-28 18:19:06 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public class AuditConfigProcessActionHandler extends ProcessActionHandler<Source>
{
	/**
	 * Parameter name for the time interval to clean audit entries.
	 */
	private static final String PARAMETER_CLEAN_INTERVAL = "cleanInterval";
	
	public void processAction() throws PortalException
	{
		String actionId = XmlUtil.readAttributeString("id", processActionNode);

		if ("commit".equals(actionId))
		{
			Number cleanInterval = (Number) getParameter(PARAMETER_CLEAN_INTERVAL);
			updateAuditConfig(cleanInterval);
		}
		
		addDefaultResponse();
	}
	
	/**
	 * Updates the time interval to clean audit entries.
	 * @param cleanInterval		the new time interval in days.
	 * @throws PortalException	if an error occur calling 
	 * 							{@link lumis.portal.audit.AuditManager}.
	 * @since 6.0.0
	 */
	private void updateAuditConfig(Number cleanInterval) throws PortalException
	{
		AuditManager auditManager = (AuditManager) ManagerFactoryInternal.getAuditManager();
		auditManager.updateCleanInterval(cleanInterval.intValue());
	}
}